package com.seadragon.app.dms.model;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name="CREDIT_CARD", uniqueConstraints = {@UniqueConstraint(columnNames = {"ACCOUNT_NUMBER"})})
public class CreditCard{
	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = IDENTITY)
	private long id;

	@Column(name="TYPE")
	private String type;

	@Column(name="NAME_APPEARED_ON_CARD")
	private String nameAppearedOnCard;

	@Column(name="ACCOUNT_NUMBER")
	private String accountNumber;

	@Column(name="EXPIREATION_DATE")
	@Temporal(TemporalType.DATE)
	private Date expirationDate;

	@Column(name="SECURITY_CODE")
	private String securityCode;

	@ManyToOne
	@JoinColumn(name="CUSTOMER_ID")
	private Customer customer;
	
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="BILLING_ADDRESS_ID")
	private Address billingAddress;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public CreditCard() {
		super();
	}

	public String getNameAppearedOnCard() {
		return nameAppearedOnCard;
	}

	public void setNameAppearedOnCard(String nameAppearedOnCard) {
		this.nameAppearedOnCard = nameAppearedOnCard;
	}

	public String getAccountNumber() {
		return accountNumber;
	}

	public void setAccountNumber(String accountNumber) {
		this.accountNumber = accountNumber;
	}

	public Date getExpirationDate() {
		return expirationDate;
	}

	public void setExpirationDate(Date expirationDate) {
		this.expirationDate = expirationDate;
	}

	public String getSecurityCode() {
		return securityCode;
	}

	public void setSecurityCode(String securityCode) {
		this.securityCode = securityCode;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Address getBillingAddress() {
		return billingAddress;
	}

	public void setBillingAddress(Address billingAddress) {
		this.billingAddress = billingAddress;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	@Override
	public boolean equals(Object obj){
		return obj!=null&&obj.getClass()==this.getClass()&&((CreditCard)obj).getAccountNumber().equals(this.accountNumber);
	}
	
	@Override
	public int hashCode(){
		return 13;
	}

}